/*
* Copyright (c) 2010-2013 Ruben Chakhmakhchyan. All rights reserved.
* 
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Eclipse Public License
* Version 1.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://opensource.org/licenses/EPL-1.0 and read it before using this file.
*/

#include "stdafx.h"
#include "CScriptableDevice.h"


CScriptableDevice::CScriptableDevice()
    : m_bstrId( NULL ),
    m_bstrUid( NULL ),
    m_bstrManufacturer( NULL ),
    m_bstrProductFamily( NULL ),
    m_bstrProductName( NULL )
{
}

CScriptableDevice::~CScriptableDevice()
{
    /*if ( m_bstrId ) ::SysFreeString( m_bstrId );
    if ( m_bstrUid ) ::SysFreeString( m_bstrUid );
    if ( m_bstrManufacturer ) ::SysFreeString( m_bstrManufacturer );
    if ( m_bstrProductFamily ) ::SysFreeString( m_bstrProductFamily );
    if ( m_bstrProductName ) ::SysFreeString( m_bstrProductName );*/
}

STDMETHODIMP CScriptableDevice::get_index( VARIANT* pVal )
{
    pVal->vt = VT_INT;
    pVal->intVal = m_deviceInfo->getDeviceInfo().index;

    return S_OK;
}

STDMETHODIMP CScriptableDevice::get_id( VARIANT* pVal )
{
    if ( m_bstrId == NULL ) m_bstrId = ::SysAllocString( m_deviceInfo->getDeviceInfo().id );

    pVal->vt = VT_BSTR;
    pVal->bstrVal = m_bstrId;

    return S_OK;
}

STDMETHODIMP CScriptableDevice::get_uid( VARIANT* pVal )
{
    if ( m_bstrUid == NULL ) m_bstrUid = ::SysAllocString( m_deviceInfo->getDeviceInfo().uid );

    pVal->vt = VT_BSTR;
    pVal->bstrVal = m_bstrUid;

    return S_OK;
}

STDMETHODIMP CScriptableDevice::get_manufacturer( VARIANT* pVal )
{
    if ( m_bstrManufacturer == NULL ) m_bstrManufacturer = ::SysAllocString( m_deviceInfo->getDeviceInfo().manufacturer );

    pVal->vt = VT_BSTR;
    pVal->bstrVal = m_bstrManufacturer;

    return S_OK;
}

STDMETHODIMP CScriptableDevice::get_productFamily( VARIANT* pVal )
{
    if ( m_bstrProductFamily == NULL ) m_bstrProductFamily = ::SysAllocString( m_deviceInfo->getDeviceInfo().productFamily );

    pVal->vt = VT_BSTR;
    pVal->bstrVal = m_bstrProductFamily;

    return S_OK;
}

STDMETHODIMP CScriptableDevice::get_productName( VARIANT* pVal )
{
    if ( m_bstrProductName == NULL ) m_bstrProductName = ::SysAllocString( m_deviceInfo->getDeviceInfo().productName );

    pVal->vt = VT_BSTR;
    pVal->bstrVal = m_bstrProductName;

    return S_OK;
}

void CScriptableDevice::setData( ImagingDevice* deviceInfo )
{
    m_deviceInfo = deviceInfo;
}

void CScriptableDevice::disposed()
{
    //m_item = NULL;
}
